/**
  ******************************************************************************
  * @file    debug_log.c
  * @author  Iron
  * @date 	 2018-07-16
  * @version v1.0
  * @brief   debug log c file
  */

/** @addtogroup DEGBU_LOG
  * @{
  */

/* includes ------------------------------------------------------------------*/
#include <stdio.h>
#include <stdarg.h>
#include "FreeRTOS.h"
#include "task.h"
#include "debug_log.h"
#include "bsp.h"

#ifndef LOG_LOCAL_LEVEL
#define LOG_LOCAL_LEVEL     DBG_LOG_DEBUG
#endif

/* private typedef -----------------------------------------------------------*/
/* private define ------------------------------------------------------------*/
#define DBG_BUF_SIZE	256

/* private macro -------------------------------------------------------------*/
/* private variables ---------------------------------------------------------*/
/* private function prototypes -----------------------------------------------*/
/* private functions ---------------------------------------------------------*/

uint32_t debug_log_timestamp(void)
{
//	return bsp_get_rtc_time(); // rtc unix timestamp
  return (xTaskGetTickCount() / portTICK_PERIOD_MS);
}

void debug_log(dbg_log_level_t level, const char* tag, const char* format, ...)
{
  va_list args;

  static char log_buf[DBG_BUF_SIZE];

  va_start(args, format);
  vsnprintf(log_buf, DBG_BUF_SIZE - 1, format, args);  // Note: rt_vsnprintf not surpport uint64_t float.
  va_end(args);

  bsp_puts(log_buf);
}

void debug_print_hex(const uint8_t *data, int32_t len)
{
  int32_t i;

  for (i = 0; i < len; i++) {
    debug_log(DBG_LOG_DEBUG, "", "%02x ", data[i]);
  }
  debug_log(DBG_LOG_DEBUG, "", "\r\n");
}

/**
  * @}
  */

/******************* (C)COPYRIGHT 2018 ***** END OF FILE *********************/
